<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="css/common.css"/>
		<link rel="stylesheet" type="text/css" href="css/lawyer_add.css"/>
		<style type="text/css">
			textarea{
				border: 1px solid #ccc;
				border-radius: 5px;
				min-height: 100px;
				padding: 10px;
			}
		</style>
	</head>
	<body>
		<form action="" method="post" class="search_box" id="form" enctype="multipart/form-data">
			<div>
				<span>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</span>
				<input type="text" name="name" placeholder="请输入姓名" />
				<input type="hidden" name="id" id="id" placeholder="请输入推广人员"/>
				<input type="hidden" name="imgpic" id="imgpic" placeholder="请输入推广人员"/>
				<input type="hidden" name="weixin"  id="weixin"  placeholder="请输入推广人员"/>
			</div>
			<div>
				<span>职务：</span>
				<input type="text" name="zw" placeholder="请输入职务" />
			</div>
			<div>
				<span>手&nbsp;&nbsp;机&nbsp;&nbsp;号：</span>
				<input type="text" name="mobile" placeholder="请输入手机号" />
			</div>
			<div>
				<span>执业证号：</span>
				<input type="text" name="cert" placeholder="请输入执业证号" />
			</div>
			<div>
				<span>地址：</span>
				<input type="text" name="address" placeholder="请输入地址" />
			</div>
			<div style="line-height: 30px;height: auto;">
				<span>擅长领域：</span>
				<div class="good_at">
					<label><input type="checkbox" name="expert" value="公司犯罪">公司犯罪</label>
					<label><input type="checkbox" name="expert" value="海事犯罪">海事犯罪</label>
					<label><input type="checkbox" name="expert" value="职务犯罪">职务犯罪</label>
					<label><input type="checkbox" name="expert" value="金融犯罪">金融犯罪</label>
					<label><input type="checkbox" name="expert" value="毒品犯罪">毒品犯罪</label>
					<label><input type="checkbox" name="expert" value="毒品犯罪">毒品犯罪</label>
					<label><input type="checkbox" name="expert" value="网络犯罪">网络犯罪</label>
					<label><input type="checkbox" name="expert" value="走私犯罪">走私犯罪</label>

					<!-- 公司犯罪,海事犯罪,职务犯罪,金融犯罪,毒品犯罪,网络犯罪,走私犯罪辩护七个内容 -->
				</div>
			</div>
			<div style="margin: 20px 0;height: auto;display: inline-block;">
				<span style="vertical-align: top;margin-top: 35px;">上传照片：</span>
				<img id="ImgPr" class="add_pic" width="120" height="120" alt="">
				<input type="file" id="up" style="display: none;" name="imgpicFile" value="" placeholder="">
			</div>
			<div style="margin: 20px 50px;height: auto;display: inline-block;">
				<span style="vertical-align: top;margin-top: 35px;">二&nbsp;&nbsp;维&nbsp;&nbsp;码：</span>
				<img class="add_pic" width="120" height="120" id="ImgPr1" alt="">
				<input type="file" style="display: none;" name="weixinFile" value="" placeholder="">
			</div>
			<div style="height: auto;">
				<span>教育背景：</span>
				<div style="flex: 1;">
					<textarea  name="jybj" style="width: 100%;"></textarea>
				</div>
			</div>
			<div style="height: auto;">
				<span>执业经验：</span>
				<div style="flex: 1;">
					<textarea id="zyjy" name="zyjy" style="width: 100%;"></textarea>
				</div>
			</div>
			<div style="height: auto;">
				<span>成功案例：</span>
				<div style="flex: 1;">
					<textarea id="cgal" name="cgal" style="width: 100%;"></textarea>
				</div>
			</div>
			<div style="height: auto;">
				<span>获得荣誉：</span>
				<div style="flex: 1;">
					<textarea id="ry" name="ry" style="width: 100%;"></textarea>
				</div>
			</div>
			<div style="height: auto;">
				<span>学术成果：</span>
				<div style="flex: 1;">
					<textarea id="xscg" name="xscg" style="width: 100%;"></textarea>
				</div>
			</div>
			<div style="height: auto;">
				<span>社会兼职：</span>
				<div style="flex: 1;">
					<textarea id="shjz" name="shjz" style="width: 100%;"></textarea>
				</div>
			</div>
			<button class="sub" data-tip = "律师列表" type="submit">提交</button>
			<button type="reset" class="reset" style="display: none;"></button>
		</form>
		
		<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="js/common.js"></script>
		<script src="js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			jQuery.browser={};(function(){jQuery.browser.msie=false; jQuery.browser.version=0;if(navigator.userAgent.match(/MSIE ([0-9]+)./)){ jQuery.browser.msie=true;jQuery.browser.version=RegExp.$1;}})();
			$(document).ready(function() {
					//获得edit信息
				 var id= $.cookie("articleId");
					 if(id && id!=''){
						$.ajax({
										type: "GET",
										url: "/lawyer/"+id,
										cache: false,
										contentType: 'application/json;utf-8',
										processData: false,
										success: function(data) {
												if (data.rel) {
													setInputValues(data.result);
													//setCheckBoxValues("expert",data.result.expert);
													$("#ImgPr").attr("src",data.result.imgpic);
													$("#ImgPr1").attr("src",data.result.weixin);
														$("#id").val(data.result.id);
														$("#imgpic").val(data.result.imgpic);
														$("#weixin").val(data.result.weixin);
												}
										 }
						 });

					 }
					 $.cookie('articleId', '');
				$('.add_pic').click(function() {
					var id = $(this).attr('id');
					$(this).siblings('input').click();
					$(this).siblings('input').uploadPreview({ Img: id, Width: 120, Height: 120 });
				});

				$('#form').submit(function (e) {
					$.ajax({
						type: "POST",
						url: "lawyer/edit",
						data: new FormData($(this)[0]), // serializes the form's elements.
						cache:false,
						contentType: false,
						processData: false,
						success: function(data){
							console.log(data);
							if(data){
								//alert(data.msg);
								if(data.rel){
									layui.use('layer', function() {
										var layer = layui.layer;
						
										layer.msg(data.msg, {
											icon: 6
										},function() {
											var text = $('.sub').attr('data-tip');
									        $(window.parent.$(".acrossTab li").each(function(){
									            if($(this).children('span').text() == text){
									                $(window.parent.$("aside").attr('data-tip',1));
									                $(this).click();
									            } else {
									                $(window.parent.$("aside li").each(function(){
									                    if ($(this).text() == text) {
									                        $(this).click();
									                    }
									                }));
									            }
									        }));
									        $('.reset').click();
										})
									})
								} else {
									layui.use('layer', function() {
										var layer = layui.layer;
										layer.msg(data.msg, {
											icon: 5
										})
									})
								}
								
							}else{
								layui.use('layer', function() {
									var layer = layui.layer;
									layer.msg('保存失败', {
										icon: 5
									})
								})
							}
						}
					});
					e.preventDefault();
				});
			});

			document.onkeydown = function(event){
				var e = event || window.event || arguments.callee.caller.arguments[0];
				if(e && e.keyCode == 116){
					event.preventDefault();
					
					$(window.parent.$('.showIframe').each(function(){
						if(!$(this).hasClass('hideIframe')){
							$(this).children('iframe').attr('src',$(this).children('iframe').attr('src'))
						}
					}))
				}
			}

			function setInputValues(data) {
					for (var p in data) {
					     $("input[name=" + p + "][type='text']").val(data[p]);
							 $("textArea[name=" + p + "]").val(data[p]);
					}
			}

			function setCheckBoxValues(key,data) {
			    $.each(data.split(","), function (index, value) {
						$("input[name="+key+"][value=" + value + "]").attr("checked", true);
					});
			}
		</script>
	</body>
</html>
